• SubLaunch(programName,docName)* - sublaunches the program with optional attached
document. Both HyperCard and the specified program will then be running, memory
permitting (at least 2 Meg!). If the arguments have no colons in them (not a pathname),
then the “Look for applications in:” etc. cards in the Home stack are consulted.
SubLaunch return 0 for success, negative numbers for Operating System errors, and small positive numbers for parameter errors, or lack of memory. To see how to handle this, and how the XFCNs can be used in concert, take a look at the “InvokeApplication” and “OsErr” handlers* below. InvokeApplication also fixes HyperCard bugs* when under MultiFinder.
on InvokeApplication progName,docName,noSubLaunch
global documents
if MultiFinder() is false then
if docName is empty then
open progName
else
open docName with progName
end if
else
if IsRunning(progName) is true then
-- Can't attach a document in this case without invoking
-- Tempo or QuicKeys. See the “PostEvent” stack for details.
doMenu progName
else
-- Not running. Launch or sublaunch it.
if the shiftKey is down or noSubLaunch is true then
-- Override: don't sublaunch, just do a normal launch.
if docName is not empty then
-- Need to move the document up to the volume root for this
-- to work properly due to MultiFinder/Hypercard bug.
if NumberOfChars(":",docName) is 0 then
-- Filename needs expanding
put GetFullPath(docName,documents) into docName
if docName is empty then
-- one reason for this would be a previous call that
-- moved the document up to the root, and the root isn't
-- on the document search path
answer "Can't find the document" with "OK"
exit InvokeApplication
end if
end if -- end NumberOfChars
-- Is this document at the root of the volume?
if FileAtRoot(docName) is false then
-- Need to move it to the root. Start by computing the
-- name of the volume.
put VolumeName(docName) into vol
if vol is empty then exit InvokeApplication
put MoveFile(docName,vol) into err
if err is not 0 then
OsErr err -- report file i/o error
exit InvokeApplication
end if
-- Document is now at the root. All we need to do is find
-- out the new name for the document.
put vol & LastPathComponent(docName) into docName
end if -- end FileAtRoot
open docName with progName
else
-- No document. Just run the application.
open progName
end if -- end docName not empty test
exit InvokeApplication
end if -- end shiftKey/override
if docName is empty then
put SubLaunch(progName) into err
else
put SubLaunch(progName,docName) into err
end if
if err is not 0 then
if err < 0 then
OsErr err
else if err is 1 then
-- Parameter error?
answer "Parameter error in sublaunch call" with "OK"